package net.minecraft.src;

import java.util.Random;

public class BlockGrinder extends BlockContainer
{

	public int blockIndexInTextureFront;

	protected BlockGrinder(int i, int j)
	{
		super(i, j, Material.rock);
	}

	public TileEntity getBlockEntity()
	{
		return new TileEntityGrinder();
	}
	
	public void onBlockRemoval(World world, int i, int j, int k)
	{
		TileEntityGrinder teg = (TileEntityGrinder)world.getBlockTileEntity(i, j, k);
		for(int l = 0; l < teg.getSizeInventory(); l++)
		{
			if(teg.hasItemInSlot(l))
			{
				ItemStack itemstack = teg.getStackInSlot(l).copy();
				Random r = new Random();
				float f = r.nextFloat() * 0.8F + 0.1F;
                float f1 = r.nextFloat() * 0.8F + 0.1F;
                float f2 = r.nextFloat() * 0.8F + 0.1F;
                float f3 = 0.05F;
				EntityItem entityitem = new EntityItem(world, (float)i + f, (float)j + f1, (float)k + f2, new ItemStack(itemstack.itemID, itemstack.stackSize, itemstack.getItemDamage()));                
                entityitem.motionX = (float)r.nextGaussian() * f3;
                entityitem.motionY = (float)r.nextGaussian() * f3 + 0.2F;
                entityitem.motionZ = (float)r.nextGaussian() * f3;
                world.entityJoinedWorld(entityitem);
			}
		}
		super.onBlockRemoval(world, i, j, k);
	}

	public void onBlockAdded(World world, int i, int j, int k)
	{
		super.onBlockAdded(world, i, j, k);
	}

	public int getBlockTextureFromSide(int i)
	{
		return (i == 3) ? blockIndexInTextureFront : blockIndexInTexture;
	}

	public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player)
	{
		TileEntityGrinder teg = (TileEntityGrinder) world.getBlockTileEntity(x, y, z);
		ModLoader.OpenGUI(player, new GuiGrinder(player.inventory, teg));
		return true;
	}
}
